package io.renren.modules.evaluate.controller;

import io.renren.common.utils.R;
import io.renren.modules.evaluate.dao.NormMesDao;
import io.renren.modules.evaluate.dao.UpLoadMapper;
import io.renren.modules.evaluate.entity.Judge;
import io.renren.modules.evaluate.entity.M;
import io.renren.modules.evaluate.service.IndexService;
import io.renren.modules.sys.controller.SysLoginController;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class IndexController {
    @Autowired
    SysLoginController sysLoginController;
    @Autowired
    NormMesDao normMesDao;
    @Autowired
    UpLoadMapper upLoadMapper;
    @Autowired
    IndexService indexService;

    @ApiOperation("啥玩楞")
    @GetMapping("index/find")
    public List<Judge> findbyid(){
        Long userid = sysLoginController.get();
        List<Judge> list = normMesDao.GetJudgeByUserId(userid);
        return list;

    }

    @ResponseBody
    @ApiOperation("根据name动态查询表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query",name="page", dataType = "int", value = "2"),
            @ApiImplicitParam(paramType = "query",name="limit", dataType = "int", value = "2")
    })
    @GetMapping("index/findByTableName")
    public List<Object> getByTableName(String name, @ApiIgnore @RequestParam(required = false) Map<String, Object> params){
        List<Object> l2 = new ArrayList<>();
        Integer page = Integer.parseInt((String)params.get("page"));
        Integer limit = Integer.parseInt((String)params.get("limit"));

        List<HashMap<String,Object>> l = upLoadMapper.getByTableName(name, page, limit);

        for (Map.Entry<String, Object> entry : l.get(1).entrySet()) {
            HashMap<String, Object> map = new HashMap<>();
            map.put("pinyin",entry.getKey());
            map.put("name",indexService.findByname(entry.getKey()));
            /*l2.add(map);*/
            l2.add(map);
        }
        l2.add(l);

        return l2;
    }





}
